<?	
	include 'lib/common.php';

	App::namespace('lib.core', false);
	App::namespace('lib.core.mvc', false);
	App::namespace('lib.core.mvc.controllers', false);
	
	header('Content-Type: text/javascript');

	$files = App::scanFiles('lib/controllers/');

	$api = array();
	
	foreach ($files as $file) 
	{
        include_once($file['path']);

        $controller = substr($file['name'], 0, -15);
        $controllerClass =  $controller . 'Controller';
        $reflection = new ReflectionClass($controllerClass);
        $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
		$controller = substr($reflection->getName(), 0, -10);

        foreach($methods as $method)
        {
            if(substr($method->name, 0, 2) == '__')
            {
                continue;
            }

            $argsInfo = $method->getParameters();
            $argsMax = count($argsInfo);
			
            $api[$controller][] = array(
                'name' => $method->name,
                'len' => $argsMax,
                'formHandler' => false
            );
        }
	}
	
	$config = array(
		'url' => 'index.php',
		'actions' => $api,
		'enableBuffer' => 10,
		'type' => 'remoting'
	);

	print 'Ext.ns("Ext.app");Ext.app.DirectAPI=' . json_encode($config);
?>